package com.atguigui.leetcode1;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 2500. 删除每行中的最大值
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/7/27 9:32
 */
public class P2500DeleteGreatestValueInEachRow {
    public static void main(String[] args) {

    }

    class Solution {
        public int deleteGreatestValue(int[][] grid) {

            // 将int[][]转成Integer[][]
            Integer[][] integerArray = new Integer[grid.length][];
            for (int i = 0; i < grid.length; i++) {
                integerArray[i] = new Integer[grid[i].length];
                for (int j = 0; j < grid[i].length; j++) {
                    integerArray[i][j] = grid[i][j]; // 自动装箱：int -> Integer
                }
            }

            // 二维数组进行排序
            for (int i = 0; i < grid.length; i++) {
                Arrays.sort(integerArray[i], Comparator.reverseOrder());
            }

            // 查找最大值
            int ans = 0;
            for (int i = 0; i < integerArray[0].length; i++) {
                int a = 0;
                for (int j = 0; j < integerArray.length; j++) {
                    a = Math.max(a, integerArray[j][i]);
                }
                ans += a;
            }

            return ans;
        }
    }
}
